using B.S.Data.MES.API.Applications.BaseData.Command.ChanXIanCommand;
using B.S.Domain.BasicData.Factory_modeling.Production_line_management;
using B.S.Infratrctrue;
using B.S.Requst;
using MediatR;

namespace B.S.Data.MES.API.Applications.BaseData.CommandHandlers.ChanXIanCommandHandlers
{
    /// <summary>
    /// 产线管理删除命令处理器
    /// </summary>
    public class DeleChanXianCommandHandlers : IRequestHandler<DeleChanXianCommand, APIRequst<int>>
    {
        private readonly IBaseRepository<Production_line_management> proRepository;

        /// <summary>
        /// 构造函数，注入仓储
        /// </summary>
        /// <param name="proRepository">产线管理仓储</param>
        public DeleChanXianCommandHandlers(IBaseRepository<Production_line_management> proRepository)
        {
            this.proRepository = proRepository;
        }

        /// <summary>
        /// 处理产线管理删除命令
        /// </summary>
        /// <param name="request">删除命令</param>
        /// <param name="cancellationToken">取消令牌</param>
        /// <returns>操作结果</returns>
        public async Task<APIRequst<int>> Handle(DeleChanXianCommand request, CancellationToken cancellationToken)
        {
            var productionLine = proRepository.GetAll().FirstOrDefault(x => x.ProductionlinePK == request.ProductionlinePK);
                productionLine.isDel = true;
                await proRepository.Update(productionLine);
           return new APIRequst<int> { Msg=RequstCode.成功.ToString(),Code=RequstCode.成功};
        }
    }
}